<?php

namespace app\api\controller;

use think\Controller;

class Banner extends Controller
{
    //banner列表
    public function banner()
    {
        //banner图
        $banner = model('common/Banner')
            -> where('status',1)
            -> order('update_time','desc')
            -> field('id,img')
            -> limit(3)
            -> select();

        //最新资讯
        $information = model('common/Information')
            -> where('status',1)
            -> field('id,img,title,content')
            -> order('create_time','desc')
            -> find();
        //游学体验
        $life = model('common/Life')
            -> order('create_time','desc')
            -> field('id,img')
            -> limit(4)
            -> select();
        $cla = model('common/Classify')
            -> field('content')
            -> find();
        //名师规划
        $teacher = model('common/Teacher')
            -> where(['classify'=>1,'status'=>1])
            -> field('id,tname,position,sex,region,recome,profile,photo')
            -> limit(2)
            -> select();
        foreach($teacher as $v){
            if ($v->sex==1){
                $v->sex = '男';
            } else {
                $v->sex = '女';
            }
        }
        //日语培训
        $course = model('common/Course')
            -> field('id,cname,score,account,img')
            -> limit(2)
            -> select();
        //留学生活
        $live = model('common/Experience')
            -> order('create_time','desc')
            -> field('id,img,title,create_time')
            -> limit(2)
            -> select();
        $data = [];
        $data['banner'] = $banner;
        $data['information'] = $information;
        $a['life'] = $life;
        $a['lifes'] = $cla;
        $data['exper'] = $a;
        $data['teacher'] = $teacher;
        $data['course'] = $course;
        $data['live'] = $live;


        if (!$data['banner']){
            return json([
                'code' => 404,
                'msg' => 'banner图为空！',
            ]);
        }
        if (!$data['information']){
            return json([
                'code' => 404,
                'msg' => '最新资讯为空！',
            ]);
        }
        /*if (!$data['lifes']){
            return json([
                'code' => 404,
                'msg' => '游学体验简介为空！',
            ]);
        }*/
        if (!$data['exper']){
            return json([
                'code' => 404,
                'msg' => '游学体验为空！',
            ]);
        }
        if (!$data['teacher']){
            return json([
                'code' => 404,
                'msg' => '名师规划为空！',
            ]);
        }
        if (!$data['course']){
            return json([
                'code' => 404,
                'msg' => '日语培训为空！',
            ]);
        }
        if (!$data['live']){
            return json([
                'code' => 404,
                'msg' => '留学生活为空！',
            ]);
        }
//        dump($data);
        return json([
            'code' => 100,
            'msg' => '请求成功！',
            'data' => $data
        ]);
    }
}
